package vete.Interfaz;

import java.awt.Component;
import java.awt.Container;
import java.util.List;
import javax.swing.JComboBox;
import javax.swing.JTextField;

/**
 *
 * @author  Lisandro
 */
public class MainFrame extends javax.swing.JFrame {

    private static final long serialVersionUID = 1L;

    /* Atributos */
    private PanelArticulos panelArticulos;
    private PanelClientes panelClientes;
    private PanelUsuarios panelUsuarios;
    private PanelProveedores panelProveedores;
    private PanelConfigurar panelConfigurar;
    private PanelComprar panelComprar;
    private PanelVender panelVender;

    /** Creates new form NewJFrame */
    public MainFrame() {
        initComponents();
        inicializar();
        this.setExtendedState(MAXIMIZED_BOTH);
//        spCliente.setDividerLocation(.70);
//        spArticulo.setDividerLocation(.70);
//        tfCuitCliente.setInputVerifier(new ValidadorCUIT());
//        tfCuitProveedor.setInputVerifier(new ValidadorCUIT());
    }

    private void inicializar() {
        panelProveedores = new PanelProveedores();
        panelClientes = new PanelClientes();
        panelArticulos = new PanelArticulos();
        panelUsuarios = new PanelUsuarios();
        panelConfigurar = new PanelConfigurar();
        panelComprar = new PanelComprar();
        panelVender = new PanelVender();

        jtpPrincipal.add("     Proveedores   ", panelProveedores);
        jtpPrincipal.add("      Clientes     ", panelClientes);
        jtpPrincipal.add("      Articulos    ", panelArticulos);
        jtpPrincipal.add("      Usuarios     ", panelUsuarios);
        jtpPrincipal.add("      Vender       ", panelVender);
        jtpPrincipal.add("      Comprar      ", panelComprar);
        jtpPrincipal.add("     Configurar    ", panelConfigurar);

        //actualizarFecha();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jtpPrincipal = new javax.swing.JTabbedPane();
        jLabel31 = new javax.swing.JLabel();
        tfUsuario = new javax.swing.JTextField();
        jbSalir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Sanatorio Veterinario Cuyo");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jtpPrincipal.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N

        jLabel31.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel31.setText("Usuario");

        tfUsuario.setEditable(false);

        jbSalir.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jbSalir.setText("Salir");
        jbSalir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jbSalirMouseClicked(evt);
            }
        });
        jbSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSalirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel31)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 666, Short.MAX_VALUE)
                        .addComponent(jbSalir)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jtpPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 905, Short.MAX_VALUE)
                        .addGap(12, 12, 12))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jtpPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel31)
                    .addComponent(tfUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbSalir))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    List aObjeto(List us) {

        List<Object> o = null;

        for (int i = 0; i < us.size(); i++) {

            o.set(i, us.get(i));

        }

        return us;
    }

private void jbSalirMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbSalirMouseClicked

    salir();

}//GEN-LAST:event_jbSalirMouseClicked

private void jbSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSalirActionPerformed
    
    salir();

}//GEN-LAST:event_jbSalirActionPerformed

    /**
     * Limpia los campos de el contenedor.
     * @param contenedor
     */
    public void limpiarCampos(Container contenedor) {

        Component[] componentes = contenedor.getComponents();

        for (int i = 0; i < componentes.length; i++) {
            if (componentes[i] instanceof JTextField) {
                ((JTextField) componentes[i]).setText("");
            } else if (componentes[i] instanceof JComboBox) {
                ((JComboBox) componentes[i]).setSelectedIndex(0);
            }
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }

    private void formWindowClosing(java.awt.event.WindowEvent evt) {

        salir();

    }

    private void salir() {

        this.dispose();
        System.exit(0);

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel31;
    private javax.swing.JButton jbSalir;
    private javax.swing.JTabbedPane jtpPrincipal;
    private javax.swing.JTextField tfUsuario;
    // End of variables declaration//GEN-END:variables
}
